home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Telnet 2.7b5 / source / main / mainseg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-08  |  4.1 KB  |  166 lines  |  [TEXT/CWIE]

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1992,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. ****************************************************************/
  13.  
  14. #ifdef MPW
  15. #pragma segment main
  16. #endif
  17.  
  18. #define GLOBALMASTER            /* Global structures are charged to us... see below */
  19. #include "event.proto.h"
  20. #include "netevent.proto.h"
  21. #include "init.proto.h"
  22. #include "network.proto.h"        // For netshut proto
  23. #include "wind.h"
  24. #include "MacBinary.h"
  25. #include "binsubs.proto.h"            // For close_mb_files proto
  26. #include "AddressXlation.h"
  27. //the following are for the unload protos
  28. #include "vgtek.proto.h"        
  29. #include "vr.h"                    
  30. #include "vr.proto.h"            
  31. #include "rsinterf.proto.h"        
  32. #include "vsem.proto.h"            
  33. #include "configure.proto.h"    
  34. #include "macros.proto.h"        
  35. #include "bkgr.proto.h"            
  36. #include "printing.proto.h"        
  37. #include "sets.proto.h"        
  38. #include "rg0.proto.h"    
  39. #include "rgmp.proto.h"        
  40. #include "parse.proto.h"
  41. #include "linemode.proto.h"    
  42. #include "tnae.h"    
  43. #include "authencrypt.proto.h"
  44. #include "mainseg.proto.h"
  45. #include "IConfig.proto.h"        
  46. #include "ae.proto.h"            
  47. #include "prefs.proto.h"
  48.  
  49. //#define    PROFILER                        //    Define to use MW profiler
  50. #ifdef    PROFILER
  51. #include     "profiler.h"
  52. #endif
  53.  
  54. Cursor *theCursors[NUMCURS];        /* all the cursors in a nice bundle */
  55.  
  56. WindRec
  57.     *screens,        /* Window Records (VS) for :    Current Sessions */
  58.     *ftplog;
  59.  
  60. short scrn=0;
  61.  
  62. TelInfoRec    *TelInfo;            /* This is defined here and externed everywhere else. */
  63.  
  64. void    main(void)
  65. {
  66.     short    i;
  67.     long    lastCount = 0;
  68.     Boolean haveNotifiedLowMemory = FALSE, memOK;
  69.     MaxApplZone();
  70.     
  71.     for (i=0; i<9; i++)
  72.         MoreMasters();
  73.         
  74. #ifdef    PERFORMANCE
  75.     ThePGlobals = nil;
  76.     if (!InitPerf(&ThePGlobals, 10, 8, TRUE, TRUE, "\pCODE", 0, "\p", FALSE, 0, 0, 0))
  77.         Debugger();
  78.     PerfControl(ThePGlobals, TRUE);
  79. #endif
  80. #ifdef    PROFILER
  81.     if (ProfilerInit(collectDetailed, microsecondsTimeBase, 1000, 30) != noErr)
  82.         DebugStr("\pError starting profiler!");
  83.     ProfilerSetStatus(false);
  84.     ProfilerClear();
  85. #endif
  86.     init();                    /* JMB 2.6 - Call all init routines */
  87.     UnloadSeg(&init);        /* Bye, bye to init routines...     */
  88.  
  89.     do {                        /* BYU - Do this forever */
  90.         UnloadSegments();
  91.         DoEvents();
  92.         if (!TelInfo->done) DoNetEvents();
  93.         
  94.         memOK = RecoverReserveMemory();
  95.         if (memOK) 
  96.             haveNotifiedLowMemory = false;
  97.         else if (!haveNotifiedLowMemory) 
  98.         {
  99.             Alert(MemoryLowAlert, NULL);
  100.             haveNotifiedLowMemory = true;
  101.         }
  102.     } while (!TelInfo->done);                        /* BYU mod */
  103.         
  104. #ifdef    PERFORMANCE
  105.     if (!PerfDump(ThePGlobals, "\pPerform.out", TRUE, 80))
  106.         DebugStr("\pDump Failed");
  107.     Debugger(); 
  108.     TermPerf(ThePGlobals);
  109. #endif
  110. #ifdef    PROFILER
  111.     if (ProfilerDump("\pProfiler.out") != noErr) {
  112.         DebugStr("\pDump Failed");
  113.         }
  114.     ProfilerTerm();
  115. #endif
  116. }
  117.  
  118. void    quit( void)
  119. {
  120.     if (TelInfo->numwindows>0)
  121.         return;
  122.  
  123.     netshut();
  124.     CloseResolver();            /* BYU 2.4.16 */
  125.  
  126.     close_mb_files();            /* BYU - Don't leave any files open! */
  127.     stopInternetConfig();
  128.     TelInfo->done = 1;            /* BYU */
  129. }
  130.  
  131. void    forcequit(void)
  132. {
  133.     quit();
  134.     ExitToShell();
  135. }
  136.  
  137. //    This is rather simple right now, but I'll make it smarter when I have the time.
  138. //void    CheckFreeMemory(void)
  139. //{
  140. //    long    space, block;
  141.     
  142. //    PurgeSpace(&space, &block);
  143.     
  144. //    if (space < (30 * 1024))
  145. //        Alert(MemoryLowAlert, NULL);
  146. //}
  147.  
  148. //    This unloads the segments that are safe to unload.  Right now, the DNR and network
  149. //    segments ARE NOT safe to unload.  Do _not_ add anything to this unless you really
  150. //    know what you are doing!  (I MEAN IT!)
  151. void    UnloadSegments(void)
  152. {
  153.     UnloadSeg(&TEKMAINunload);
  154.     UnloadSeg(&ICRunload);
  155.     UnloadSeg(&CONFIGUREunload);
  156.     UnloadSeg(&MACROSunload);
  157.     UnloadSeg(&FTPServerUnload);
  158.     UnloadSeg(&PrintingUnload);
  159.     UnloadSeg(&SETSunload);
  160.     UnloadSeg(&TEKNULLunload);
  161.     UnloadSeg(&TEKMacPicunload);
  162.     UnloadSeg(&LinemodeUnload);
  163.     UnloadSeg(&ICUnload);
  164.     UnloadSeg(&AEunload);
  165.     UnloadSeg(&PREFSUnload);
  166. }